﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Specialized;
using WP.DB;
using WP.RM.DataEntity;
using WP.Commons;

namespace WP.RM.DataAccess
{
    public class rmSTDSalaryInputDAL
    {
        string mstrFields_Detail = "WorkDate,PrdYear,PrdMonth,WorkShopSeqNo,WorkerID,WorkPositionSeqNo,STDSalary,DaySTDSalary,WorkDays,WorkDaysSalary,HolidayDays,HolidayDaysSalary,LeaveDays,WorkSalary,Remark,Posted";
        public bool UpdateDetail(DBAccess dbcon, DataRow drDtl)
        {
            string strSQL = "SELECT Period,StPrdDate FROM MPERIOD where StPrdDate<='{0}' and EnPrdDate>='{0}'";
            strSQL = string.Format(strSQL, drDtl["WorkDate"]);
            DataRow drPrd = dbcon.GetDataFirstRow(strSQL);
            {
                drDtl["PrdYear"] = CvtFunc.ToDateTime(drPrd["StPrdDate"]).Year.ToString();
                drDtl["PrdMonth"] = CvtFunc.ToString(drPrd["Period"]);
            }
            DataFunctions.UpdateTable(dbcon, mstrFields_Detail, "rmWorkerSTDSalary", drDtl, FormStatus.Update);
            return true;
        }

        public bool AddDetail(DBAccess dbcon, DataRow drDtl)
        {
            string strSQL = "SELECT Period,StPrdDate FROM MPERIOD where StPrdDate<='{0}' and EnPrdDate>='{0}'";
            strSQL = string.Format(strSQL, drDtl["WorkDate"]);
            DataRow drPrd = dbcon.GetDataFirstRow(strSQL);
            {
                drDtl["PrdYear"] = CvtFunc.ToDateTime(drPrd["StPrdDate"]).Year.ToString();
                drDtl["PrdMonth"] = CvtFunc.ToString(drPrd["Period"]);
            }
            DataFunctions.UpdateTable(dbcon, mstrFields_Detail, "rmWorkerSTDSalary", drDtl, FormStatus.AddNew);
            return true;
        }

        public bool Posted(DBAccess dbcon, string strRecID)
        {
            string strSQL = "Update rmWorkerSTDSalary Set Posted=1 where RecID='"+ strRecID  +"'";
            dbcon.ExecuteSql(strSQL);
            return true;
        }
    }
}
